package com.zeus.base.smscenter.controller;

import com.zeus.base.privilege.model.TbCompanyRoleMenu;
import com.zeus.base.privilege.service.ICompanyRoleMenuService;
import com.zeus.base.privilege.utils.ResultModel;
import com.zeus.base.privilege.utils.StringUtil;
import com.zeus.base.smscenter.common.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * 企业角色授权Controller
 * Created by ShanFei on 2017-03-21.
 */
@RestController
@RequestMapping("/controller/companyRoleMenuAuthority")
public class CompanyRoleMenuController extends BaseController {
    @Autowired
    private ICompanyRoleMenuService iCompanyRoleMenuService;

    /**
     * 根据参数查询角色菜单授权
     *
     * @param productLineId
     * @param applicationId
     * @param companyRoleId
     * @return
     */
    @RequestMapping(value = "/findListRoleMenuByParams", method = RequestMethod.POST)
    @ResponseBody
    public ResponseEntity<ResultModel> findListRoleMenuByParams(@RequestParam(name = "productLineId", required = false) Integer productLineId, @RequestParam(name = "productLineCode", required = false) String productLineCode, @RequestParam(name = "applicationId", required = false) Integer applicationId, @RequestParam(name = "companyRoleId", required = true) String companyRoleId, @RequestParam(name = "companyId", required = false) String companyId, @RequestParam(name = "openFlag", required = false) Integer openFlag) {
        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("productLineId", productLineId);
        //如果productLineCode不为空并且等于'configUtil',从配置文件中取值
        if (StringUtil.isNotEmpty(productLineCode) && productLineCode.equals("configUtil"))
            params.put("productLineCode", getConfigUtil().getProductLineCode());
        else if (StringUtil.isNotEmpty(productLineCode) && !productLineCode.equals("configUtil"))
            params.put("productLineCode", productLineCode);
        params.put("applicationId", applicationId);
        params.put("companyRoleId", companyRoleId);
        params.put("companyId", companyId);
        params.put("openFlag", openFlag);
        List<TbCompanyRoleMenu> list = iCompanyRoleMenuService.findListRoleMenuByParams(params);
        return new ResponseEntity<ResultModel>(new ResultModel(true, 0, list), HttpStatus.OK);
    }

}
